Component({
    properties: {
        id: Number
    },
    data: {
        lineupList: {}
    },
    methods: {
        lineupListData() {
            wx.request({
                url:'https://wxapi.db101.cn/v1/jcc/favorites/list',
                method: 'POST',
                data: {
                    // @ts-ignore
                    "userId": wx.getStorageSync('user').id
                },
                header: {
                    'content-type': 'application/json' // 默认值
                },
                success: (res) => {
                    // @ts-ignore
                    this.setData( {lineupList: res.data.data})
                }
            })
        },
        openLineupDetail(e: any) {
            // @ts-ignore
            wx.navigateTo({
                url: `/pages/lineup-detail/lineup-detail?id=${e.target.dataset.id}`,
            })
        },
        cancelFav(e: any) {
            wx.request({
                url:'https://wxapi.db101.cn/v1/jcc/favorites/delete',
                method: 'POST',
                data: {
                    // @ts-ignore
                    "userId": wx.getStorageSync('user').id,
                    // @ts-ignore
                    "lineupId": e.target.dataset.id
                },
                header: {
                    'content-type': 'application/json' // 默认值
                },
                success: (res) => {
                    // @ts-ignore
                    if (res.data.code == 200) {
                        wx.showToast({ title: '取消收藏成功', icon: 'none' });
                        this.lineupListData();
                    }
                }
            })
        }
    },
    lifetimes: {
        attached: function() {
            // @ts-ignore
            // 在组件实例进入页面节点树时执行
            // @ts-ignore
            this.lineupListData();
        },
        detached: function() {
            // 在组件实例被从页面节点树移除时执行
        },
    }
})
